package com.example.administrator.familfinalcialmanagement;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.multidex.MultiDex;

import com.example.administrator.familfinalcialmanagement.greendao.gen.DaoMaster;
import com.example.administrator.familfinalcialmanagement.greendao.gen.DaoSession;
import com.example.administrator.familfinalcialmanagement.util.LogUtil;

/**
 * Created by Administrator on 2019/3/26.
 *      /**
 *          * 1.loadAll();----------查询所有的数据
 *          * 2.条件查询---查询单个字段 获取对象-----eq方法
 *          * TaskPath taskPath = mTaskPathDao.queryBuilder().where(TaskPathDao.Properties.Task_name.eq("小红帽")).unique();
 *          * 3.条件查询---查询不是该字段内容的 对象有哪些---notEq方法
 *          * List mtaskPath = mTaskPathDao.queryBuilder().where(TaskPathDao.Properties.Task_name.notEq("小黄人")).list();
 *          * 4.条件查询--模糊查询之包含某个特殊字的查询--queryLike方法
 *          *  List mtaskPath = mTaskPathDao.queryBuilder().where(TaskPathDao.Properties.Task_name.like("小%")).list();
 *          */


public class GRApplication extends Application {

    boolean isShow = true;
    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    int TAG = 0x1314;
    private DaoSession mDaoSession;
    private Context context;
    public static GRApplication instance;

    public static GRApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        //初始化log工具
        LogUtil.init(isShow);

        //初始化数据库
        setDatabase();
    }


    private void setDatabase() {
        mHelper = new DaoMaster.DevOpenHelper(this, "notes_db", null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return db;
    }

    //分个包防止65533
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
